import java.util.Scanner;

/**
 * Created With IntelliJ IDEA
 * Description:牛客网：KY11 二叉树遍历
 * <a href="https://www.nowcoder.com/practice/4b91205483694f449f94c179883c1fef?tpId=60&&tqId=29483&rp=1&ru=/activity/oj&qru=/ta/tsing-kaoyan/question-ranking">...</a>
 * User: DELL
 * Data: 2023-01-17
 * Time: 23:23
 */

public class Main {
    static class TreeNode {
        char val;
        TreeNode left;
        TreeNode right;
        public TreeNode(char val) {
            this.val = val;
        }
    }
    private static int index;
    public static void main(String[] args) {
        //读入字符串
        Scanner scanner = new Scanner(System.in);
        String source = scanner.nextLine();
        //初始化index的值，防止重复使用导致出错
        index = 0;
        //重建二叉树
        TreeNode root = rebuildTree(source);
        //中序遍历并输出二叉树
        inOrder(root);
    }

    private static TreeNode rebuildTree(String source) {
        //这里不需要考虑i是否越界的问题，因为只要输入的是合法的先序
        //遍历字符串，一定可以正好构造出一颗完整的二叉树
        char ch = source.charAt(index);
        index++;
        if (ch == '#') {
            return null;
        }
        TreeNode node = new TreeNode(ch);
        node.left = rebuildTree(source);
        node.right = rebuildTree(source);
        return node;
    }
    //中序遍历二叉树
    private static void inOrder(TreeNode root) {
        if (root == null) {
            return;
        }
        inOrder(root.left);
        System.out.print(root.val + " ");
        inOrder(root.right);
    }
}